<template>
  <div class="page">
    <template v-if="AppleAssembleList.length">
    <div class="weui-cells">
      <a class="weui-cell weui-cell_access" v-for="(item,index) in AppleAssembleList" :key="index" @click="goDetail(item)">
        <div class="weui-cell__bd col_left">
          <div >{{item.cusName}}</div>
          <!-- <div v-else>{{item.id}}</div> -->
          <p>{{item.time}}</p>
        </div>
        <div class="weui-cell__bd col_imd">{{item.allSum}}元</div>
        <div class="weui-cell__ft col_right">查看详细</div>
      </a>

    </div>
    </template>
    <div class="weui-cell" v-if="!AppleAssembleList.length" >
      <p style="display:flex;justify-content: center;width: 100%">暂无数据</p>

    </div>
  </div>
</template>

<script>
  import * as appId from "@/utils/util"
  import {getTIme} from "@/utils/util"
export default {
  data () {
    return {
      result:[],
      AppleAssembleList:[],
      pageNo:1,
      pageSize:10
    }
  },
  onPullDownRefresh(){
     console.log('down')
      if(this.result.length){
     this.pageNo++;
    }

     this.getList()

  },
  onShow(){
    wx.setNavigationBarTitle({
      title: "提成列表"
    })
    this.userInfo =wx.getStorageSync('userInfo')&&JSON.parse(wx.getStorageSync('userInfo'))
    if(this.userInfo) {
      this.phone=this.userInfo.mobileNo;
      this.userId=this.userInfo.baseUserId;
      this. getList()

    }else{
      wx.showToast({
        title:'请先登录',
        icon: 'none',
        duration: 2000
      })
    }
  },
  methods: {
    changeTime(time){
        var commonTime = "";
        if(time){
            var unixTimestamp = new Date(time*1) ;
            commonTime = unixTimestamp.toLocaleString();
        }
         return commonTime;
    },
    goDetail(item){
      let url=`/pages/percentagedetail/main?id=${item.id}`;
      wx.navigateTo({ url })
    },
    getList(){
      let that=this;
      this.$http.request({
                method:"post",
                url:"/v1.0/appletLogin/myCommissionList",
                body:{
                  "appid":appId.appId,
                  	"phone":this.phone,
                  	"pageNo":this.pageNo,
                  	"pageSize":this.pageSize,
                  	"userId":this.userId
                }
      }).then((data)=>{
        if(data.code==0){
          this.result=data.result;
          if (that.pageNo > 1) {
            that.AppleAssembleList.push(...data.result)
          }else{
            that.AppleAssembleList=data.result;
          }
          that.AppleAssembleList.forEach((a,i)=>{
            a.time=getTIme(a.staTime)
          })
          if(!data.length){
            // wx.showToast({
            //   title: '暂无更多数据',
            //   icon: 'none',
            //   duration: 2000
            // })
          }
        }else{
          wx.showToast({
            title: `${data.message}`,
            icon: 'none',
            duration: 2000
          })
        }
      })
    }
  },

  created () {
  }
}
</script>

<style scoped>
.col_left{
  width: 8em;
}
.col_left div{
  color: #333;
}
.col_left p{
  font-size: 0.8em;
  color: #999;
}
.col_imd{
  color: #FF787E;
}
.col_right{
  color: #999;
  font-size: 0.8em;
}
</style>
